<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath();
%>
<jsp:include page="/WEB-INF/page/auth/_header.jsp"></jsp:include>
<body>
	<jsp:include page="/WEB-INF/page/auth/header.jsp"></jsp:include>
	<div id="middle">
		<jsp:include page="/WEB-INF/page/auth/menu.jsp"></jsp:include>
		<div id="right">
		    <div id="course_student_signtb">
		        <form id="course_student_signForm" class="m10">
		           	 学期：<select class="form-control1" name="termId" id="termId" onchange="changeTerm(this.text)"></select>
		           	 学籍类型：<select class="form-control1" name="studyType" id="studyType" onchange="changeStudy(this.value)">
		           	 			<option value="1">初中部</option>
		           	 			<option value="2">高中部</option>
		           	 	    </select>
		                              年级：<select class="form-control1" name="gradeType" id="gradeType" onchange="searchClazz(this.value)"></select>
					 班级：<select class="form-control1" name="clazz" id="clazz"></select>
					 课程名称:<select id="courseId" name="courseId" class="form-control1" style="width:150px;"></select>
					 <div class="mt10">
			                              学生姓名:<input id="studentName" name="studentName" class="form-control1" style="width:100px;"/>
			            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-search'" onclick="searchForm('course_student_sign')">查询</a>
			            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-clear'" onclick="resetForm('course_student_sign')">重置</a>
			        	<a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-save'" onclick="exportExcel('course_student_sign','<%=basePath%>/sys/course/studentSign/export')">导出为EXCEL</a>
		        	</div>
		        </form>
		    </div>
		    <table id="course_student_signdg">
		        <thead>
		            <tr>
		            	<th data-options="field:'courseType',title:'课程分类'"></th>
		            	<th data-options="field:'courseNo',title:'课程编号'"></th>
		                <th data-options="field:'courseName',title:'课程名称'"></th>
		                <th data-options="field:'classTeacher',title:'辅导老师'"></th>
		                <th data-options="field:'signClassDate',title:'上课时间'"></th>
		                <th data-options="field:'gradeClazz',title:'学生班级'"></th>
		                <th data-options="field:'studentNum',title:'学生学号'"></th>
		                <th data-options="field:'studentName',title:'学生姓名'"></th>
		            </tr>
		        </thead>
		    </table>
		</div>
	</div>
	<jsp:include page="/WEB-INF/page/auth/_footer.jsp"/>
	<script src="<%=basePath %>/js/datagrid-helper.js" type="text/javascript"></script>
	<script type="text/javascript">
		var url = basePath + "/sys/course/studentSign";
        $(function(){
            initTermList();
            loadDatagrid("course_student_sign", url);
            initCourseList();
        })
        function loadDatagrid(cf, url){
			dgEditIndex[cf]=-1;
			$("#"+cf+"dg").datagrid({
				url: url + "/pageQuery",
				rownumbers:true,
				striped:true,
				border:false,
				pagination:true,
				pageSize:30,
				fitColumns:true,
				singleSelect: true,
				fit: true,
				toolbar: '#'+cf+'tb',
				queryParams: {
					termId: $("#termId").val(),
					studyType: $("#studyType").val()
				},
				onLoadSuccess: function(data){
			        $(".note").tooltip({
				        onShow: function () {
					        $(this).tooltip('tip').css({
					       		borderColor: '#000'
					        });
				        }
			        });
				}
			})
		}
        function changeTerm(text){
        	initGradeList(text);
        	$("#gradeType").val("");
        	$("#clazz").val("");
        	$("#courseId").val("");
        }
        function changeStudy(v){
        	changeTerm($("#termId").find("option:selected").text());
        	initCourseList();
        }
        function initTermList(){
            $.ajax({
                url: basePath + "/termList",
                type: 'POST',
                dataType: 'json',
                error : function(data) {
                    $.messager.progress('close');
                    $.messager.alert('系统提示', data.msg, 'error');
                },
                success: function (data) {
                	var html = "";
                	for(var i in data) {
                		html += "<option value='"+data[i].id+"'>"+data[i].termName+"</option>";
                	}
                    $("#termId").html(html);
                    initGradeList(data[0].termName);
                }
            });
        }
        function initGradeList(termName) {
        	var termYear = termName.substring(0, termName.indexOf("-"))
        	$.ajax({
         		url : basePath + "/studnetGradeByTermYear",
         		type : "get",
         		dataType : "json",
         		data: {
         			termYear: termYear,
         			studyType: $("#studyType").val()
         		},
         		async : false,
         		success : function(data) {
         			var html = '<option value="">请选择</option>';
         			for(var i in data){
         		        html += "<option value='"+data[i].value+"'>"+ data[i].text +"</option>";
         		    }
         			$("#gradeType").html(html);
         			$("#gradeType").trigger("onchange");
         		}, error:function(){
         			alert("查询年级异常");
          		}
            });
        }
        function searchClazz(gradeType) {
        	if(!gradeType){
        		$("#clazz").val("");
        		return;
        	};
        	$.ajax({
         		url : basePath + "/getFullClazz?grade=" + gradeType,
         		type : "GET",
         		dataType : "json",
         		async : false,
         		success : function(data) {
         			var html = '<option value="">请选择</option>';
         			for(var i in data){
         		        if (data.hasOwnProperty(i)) {
         		        	html += "<option value='"+data[i]+"'>"+ data[i] +"班</option>";
         		        };
         		    }
         			$("#clazz").html(html);
         		}, error:function(){
         			alert("查询班级异常");
          		}
            });
        }
        function initCourseList() {
        	$.ajax({
         		url : basePath + "/studyCourse",
         		type : "post",
         		dataType : "json",
         		data: {
         			studyType: $("#studyType").val()
         		},
         		async : false,
         		success : function(data) {
         			var html = '<option value="">请选择</option>';
         			for(var i in data){
         		        html += "<option value='"+data[i].id+"'>"+ data[i].courseNo+""+data[i].courseName +"</option>";
         		    }
         			$("#courseId").html(html);
         		}, error:function(){
         			alert("查询年级异常");
          		}
            });
        }
    </script>
</body>
</html>